/*
 * Package il.ac.biu.cs.grossmm.test.SimpleProtocol
 * File Response.java
 * 
 * This is a part of presence service framework API. 
 * See javadoc for more information.
 *  
 * Copyright (C) 2006 Grossmann Mark
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.

 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 */
package il.ac.biu.cs.grossmm.foo.protocol;

public class Response extends Message {
	final int code;
	final String message;
	
	
	public Response(Request request, int code)
	{
		this(request.getTransactionId(), code, "");
	}
	
	public Response(Request request, int code, String message) {
		this(request.getTransactionId(), code, message);
	}
	
	/**
	 * @param code
	 * @param message
	 */
	public Response(String tid, int code, String message)
	{
		super(tid);
		this.code = code;
		this.message = message;
	}
	
	
	/**
	 * Gets response code
	 * @return response code
	 */
	public int getCode() {
		return code;
	}

	/**
	 * Gets human-readable message for this response
	 * @return human-readable message for this response
	 */
	public String getMessage() {
		return message;
	}

	@Override
	public String toString()
	{
		return code + " " + message;
	}
	
	public StringBuffer toStringBuffer() {
		StringBuffer sb = new StringBuffer(tid);
		sb.append(Message.PARAM_DELIMETER);
		sb.append(code);
		sb.append(Message.PARAM_DELIMETER);
		sb.append(message);
		sb.append(Message.MSG_DELIMETER);
		
		return sb;
	}
}
